<template>
  <div class="aui-card-list">
    <uni-list-query-card :queryShow="queryShow" @query-click="getDataList()" @click="(e)=>{this.queryShow=e}" @searchReset="searchReset()">
      <el-col :span="6">
        <el-form-item label="模板编号">
          <el-input v-model="dataForm.templateId" placeholder="模板编号" clearable></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="模板名称">
          <el-input v-model="dataForm.templateName" placeholder="模板名称" clearable></el-input>
        </el-form-item>
      </el-col>
    </uni-list-query-card>
    <el-card shadow="never" class="aui-card-list-body">
      <vxe-toolbar :setting="{immediate:true}">
        <template v-slot:buttons>
          <el-button v-if="$hasPermission('msg:msgRecordTemplate:save')" type="primary" @click="addOrUpdateHandle()">{{
            $t('add') }}</el-button>
          <el-button v-if="$hasPermission('msg:msgRecordTemplate:delete')" type="danger" @click="deleteHandle()">{{
            $t('deleteBatch') }}</el-button>
        </template>
        <template v-slot:tools>
          <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
          <el-dropdown trigger="click" style="padding-left: 5px;" placement="bottom">
            <el-button icon="el-icon-download" circle>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item icon="el-icon-bottom" @click.native="exportHandle(true)">导出当前页</el-dropdown-item>
              <el-dropdown-item icon="el-icon-download" @click.native="exportHandle()">全部导出
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </vxe-toolbar>
      <vxe-table ref="xTable" :loading="dataListLoading" class="vxe-table-element" auto-resize @select-change="dataListSelectionChangeHandleVex" @select-all="dataListSelectionAllChangeHandleVex" :data="dataList">
        <vxe-table-column type="checkbox" align="center" width="60"></vxe-table-column>
        <!-- <vxe-table-column field="appId" title="所属应用">
        </vxe-table-column> -->
        <vxe-table-column field="templateId" title="模板编号">
        </vxe-table-column>
        <vxe-table-column field="templateName" title="模板名称">
        </vxe-table-column>
        <vxe-table-column field="signatureText" title="签名">
        </vxe-table-column>
        <vxe-table-column field="content" title="正文模板">
        </vxe-table-column>
        <!-- <vxe-table-column field="creator" title="创建者">
        </vxe-table-column> -->
        <vxe-table-column field="updateDate" title="更新时间" width="160">
        </vxe-table-column>
        <vxe-table-column title="handle" fixed="right" align="center" :width="200" :show-overflow="false">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('msg:msgRecordTemplate:update')" type="text" size="small" icon="el-icon-edit" @click="addOrUpdateHandle(scope.row)">{{ $t('update') }}</el-button>
            <el-button v-if="$hasPermission('msg:msgRecordTemplate:delete')" type="text" size="small" icon="el-icon-delete" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
            <el-button type="text" icon="el-icon-mobile" size="small" @click="sendImitate(scope.row.id)">{{ '模拟发送' }}
            </el-button>
          </template>
        </vxe-table-column>
      </vxe-table>
      <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
      <send-imitate v-if="sendImitateVisible" ref="sendImitate"></send-imitate>
    </el-card>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './msgRecordTemplate-add-or-update'
import SendImitate from './msgRecordTemplate-send-imitate' // 模拟发送
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      sendImitateVisible: false,
      searchShow: true,
      mixinViewModuleOptions: {
        getDataListURL: '/msg/msgRecordTemplate/page',
        getDataListIsPage: true,
        deleteURL: '/msg/msgRecordTemplate',
        deleteIsBatch: true,
        exportURL: '/msg/msgRecordTemplate/export'
      },
      dataForm: {
        appId: '',
        signatureCode: '',
        templateId: '',
        templateName: ''
      }
    }
  },
  components: {
    AddOrUpdate,
    SendImitate
  },
  methods: {
    // 新增 / 修改
    addOrUpdateHandle (row) {
      let id
      if (row) {
        id = row.id
      }
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm.id = id
        this.$refs.addOrUpdate.init()
      })
    },
    sendImitate (id) {
      this.sendImitateVisible = true
      this.$nextTick(() => {
        this.$refs.sendImitate.dataForm.id = id
        this.$refs.sendImitate.init()
      })
    }
  }
}
</script>
